package com.sqoq.downloader3.ui

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.sqoq.downloader3.R
import com.sqoq.downloader3.base_ddg.BaseActivity_ddg


class TitleView_ddg(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
    LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
    private var title: TextView?
    private var dsadsadsewq = "ewqwe432"

    @JvmOverloads
    constructor(context: Context?, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : this(
        context,
        attrs,
        defStyleAttr,
        0
    )


    init {
        LayoutInflater.from(context).inflate(R.layout.title_ddg, this)
        title = findViewById(R.id.tvTitle_ddg)
        findViewById<ImageView>(R.id.ivBack_ddg).setOnClickListener {
            if (context is Fragment) {
                context.activity?.finish()
            } else if (context is BaseActivity_ddg<*>) {
                context.showBackAd()
            } else if (context is Activity) {
                context.finish()
            }
        }
    }

    fun setTitleDdg(text: String) {
        title?.text = text
    }

    fun setThemeColor(color: Int) {
        findViewById<ImageView>(R.id.ivBack_ddg).setColorFilter(color)
        title?.setTextColor(color)
    }

    fun setBackClickListener(l: OnClickListener) {
        findViewById<ImageView>(R.id.ivBack_ddg).setOnClickListener(l)
    }
}